package com.yuanyu.mapper.mysqlMapper;

import com.yuanyu.model.entity.MainTable;
import com.yuanyu.model.vo.MainTableVO;
import com.yuanyu.model.vo.MainVO;
import com.yuanyu.model.vo.ProcessVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MainTable_Mapper {

//    int addTableTime(Main main);
//
//    Main selTableTime(String input_Case);

    @Select("SELECT COUNT(*) FROM main_table;")
    Integer selAllTable();

    @Select("select * from main_table ORDER BY urgent DESC ,start_time DESC LIMIT #{number},10")
    List<MainTable> selPageTable(Integer number);

    List<MainTable> selFuzzyPageTable(@Param("mainTableVO") MainVO mainTableVO, @Param("number")Integer number);
    Integer selFuzzy(@Param("mainTableVO") MainVO mainTableVO);

    @Select("select * from main_table m where m.Case = #{Case}")
    MainTable selByCase(String Case);

    @Update("UPDATE main_table m SET state = #{state} WHERE m.Case = #{Case}")
    int updateState(@Param("Case")String Case,@Param("state")String state);

    @Update("UPDATE main_table m SET Number_of_downlines = 1 WHERE m.Case = #{Case}")
    int updateNumberOfDownlines(@Param("Case")String Case);

    @Update("UPDATE main_table m SET production_processes_1 = #{processVO.production_processes_1}," +
            "production_processes_2 = #{processVO.production_processes_2}," +
            "production_processes_3 = #{processVO.production_processes_3}," +
            "production_processes_4 = #{processVO.production_processes_4}," +
            "production_processes_5 = #{processVO.production_processes_5}," +
            "production_processes_6 = #{processVO.production_processes_6}," +
            "production_processes_7 = #{processVO.production_processes_7}," +
            "production_processes_8 = #{processVO.production_processes_8}," +
            "production_processes_9 = #{processVO.production_processes_9}," +
            "production_processes_10 = #{processVO.production_processes_10}," +
            "urgent = #{processVO.urgent},"+
            "state = '0'" +
            " WHERE m.Case = #{processVO.Case} and m.state != '1' and m.state != '2' ")
    int updateByCaseProcess(@Param("processVO")ProcessVO processVO);

    @Update("UPDATE main_table m " +
            "SET m.start_time = CASE " +
            "    WHEN m.Case = #{Case} AND m.start_time IS NULL THEN NOW() " +
            "    ELSE m.start_time " +
            " END " +
            " WHERE m.Case = #{Case} AND start_time IS NULL;")
    void updateByCaseFormStartTime(@Param("Case")String Case);

    @Update("UPDATE main_table m " +
            "SET m.end_time = NOW() "+
            " WHERE m.Case = #{Case}")
    void updateByCaseFormEndTime(@Param("Case")String Case);

    void addMainTable(MainTable mainTable);
}
